package br.com.projetoFinalAvancado;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ItemListBaseAdapter extends BaseAdapter {

	private ArrayList<PacEmpreend> itemDetalhesArrayList;
	private LayoutInflater inflater = null;
	
	public ItemListBaseAdapter(Context context, ArrayList<PacEmpreend> arrayList){
		itemDetalhesArrayList = arrayList;
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	public int getCount() {
		return itemDetalhesArrayList.size();
	}

	public Integer getItem(int position) {
		return itemDetalhesArrayList.get(position).getPacId();
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView == null){
			convertView = inflater.inflate(R.layout.item_lista_fragment, null);
			holder = new ViewHolder();
			holder.txt_titulo = (TextView) convertView.findViewById(R.id.titulo);
			holder.txt_municipio = (TextView) convertView.findViewById(R.id.municipio);
			holder.txt_siglaUF = (TextView) convertView.findViewById(R.id.siglaUF);
			holder.txt_pacId = (TextView) convertView.findViewById(R.id.pacId);
			
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		} 
		
		holder.txt_titulo.setText(itemDetalhesArrayList.get(position).getTitulos());
		holder.txt_municipio.setText(itemDetalhesArrayList.get(position).getMunicipios());
		holder.txt_siglaUF.setText(itemDetalhesArrayList.get(position).getSiglaUF());
		holder.txt_pacId.setText("" + itemDetalhesArrayList.get(position).getPacId());
				
		return convertView;
	}
	
	static class ViewHolder {
		TextView txt_municipio;
		TextView txt_titulo;
		TextView txt_siglaUF;
		TextView txt_pacId;
	}

}
